package pl.kosmowska.ewelina.client.app.activity.places;

import pl.kosmowska.ewelina.client.app.requestfactory.OutcomeDataRequest;
import pl.kosmowska.ewelina.client.app.requestfactory.dto.OutcomeDataProxy;
import pl.kosmowska.ewelina.client.app.requestfactory.dto.SavingsDataProxy;

import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.google.web.bindery.requestfactory.shared.RequestFactory;

public class SavingsEditPlace extends Place {

	  @Prefix("DodajZmienPlanOszczedzania")
	  public static class Tokenizer implements PlaceTokenizer<SavingsEditPlace> {

	    private RequestFactory requestFactory;
	    
	    public Tokenizer(RequestFactory requestFactory) {
	      this.requestFactory = requestFactory;
	    }
	    	    
	    @Override
	    public String getToken(SavingsEditPlace place) {
	      String s = "";
	      if (place.getSavingsDataId() != null) {
	        s = requestFactory.getHistoryToken(place.getSavingsDataId());
	      } else if (place.getSavingsData() != null) {
	        s = requestFactory.getHistoryToken(place.getSavingsData().stableId());
	      } else {
	        s = "new"; 
	      }
	      return s;
	    }

	    /**
	     * from - url activated
	     */
	    @Override
	    public SavingsEditPlace getPlace(String token) {
	      EntityProxyId<SavingsDataProxy> SavingsDataId = null;
	      if (token == null || token.trim().length() == 0 || token.equals("new") == true) {
	        // new
	      } else {
	        SavingsDataId = requestFactory.<SavingsDataProxy> getProxyId(token);
	      }
	      return new SavingsEditPlace(SavingsDataId);
	    }

	  }
	     
	  /**
	   * from app place move
	   */
	  private SavingsDataProxy savingsData;
	  
	  /**
	   * from url place move
	   */
	  private EntityProxyId<SavingsDataProxy> savingsDataId;
	  
	  /**
	   * constructor - from app new place
	   */
	  public SavingsEditPlace() {
	    this.savingsDataId = null;
	    this.savingsData = null;
	  }

		private OutcomeDataProxy outcomeDataProxy;
		private OutcomeDataRequest outcomeRequest;

		public OutcomeDataProxy getOutcomeDataProxy() {
			return outcomeDataProxy;
		}

		public OutcomeDataRequest getOutcomeRequest() {
			return outcomeRequest;
		}
	  
	  /**
	   * constructor - from app place move
	   * @param walletData
	   */
	  public SavingsEditPlace(SavingsDataProxy SavingsData) {
	    this.savingsDataId = null;
	    this.savingsData = SavingsData;
	  }

	  /**
	   * constructor - from url move
	   * @param walletDataId
	   */
	  public SavingsEditPlace(EntityProxyId<SavingsDataProxy> SavingsDataId) {
	    this.savingsDataId = SavingsDataId;
	  }
	  

	  public SavingsEditPlace(OutcomeDataProxy outcomeDataProxy,
			OutcomeDataRequest req) {
			this.outcomeDataProxy=outcomeDataProxy;
			this.outcomeRequest=req;
	}



	public EntityProxyId<SavingsDataProxy> getSavingsDataId() {
		    return savingsDataId;
		  }
	  
	  public SavingsDataProxy getSavingsData() {
		    return savingsData;
		  }
	 
	}


